package edu.DBUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class DBConnection {
	private final static String URL; 
	private final static String USERNAME;
	private final static String PASSWORD;
	private final static String CLASSNAME;
	static{
		Properties prop = new Properties();
		try {
			prop.load(DBConnection.class.getResourceAsStream("/jdbc.properties"));
		} catch (Exception e) {
			System.out.println("jdbc.properties file not found,error massage is"+e.getMessage());
		}
		URL=prop.getProperty("jdbc.url");
		USERNAME=prop.getProperty("jdbc.userName");
		PASSWORD=prop.getProperty("jdbc.passWord");
		CLASSNAME=prop.getProperty("jdbc.className");
		try {
			Class.forName(CLASSNAME);
		} catch (Exception e) {
			System.out.println("Class not found,error massage is"+e.getMessage());
		}
	}
		public static Connection getConnection(){
			Connection connection = null;
			try {
				connection=DriverManager.getConnection(URL,USERNAME,PASSWORD);
			} catch (Exception e) {
				System.out.println("database connection error,massage is"+e.getMessage());
			}
			return connection;
		}
		public static void CloseConnection(Connection connection) {
			if(connection!=null)
			{
				try {
					connection.close();
				} catch (Exception e) {
					System.out.println("database close error,massage is"+e.getMessage());
				}	
		}
	}
	

}
